package java10;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.util.Properties;
public class DruidTest01 {
    public static void main(String[] args){
        //导入jar包
        //定义配置文件
        //加载配置文件
        Properties pro = new Properties();
        InputStream is = DruidTest01.class.getClassLoader().getResourceAsStream("druid.properties");
        try {
            pro.load(is);
            //获取连接池对象
            DataSource ds = DruidDataSourceFactory.createDataSource(pro);
            //获取连接
            Connection conn = ds.getConnection();
            System.out.println(conn);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if(is != null){
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
